/*

package com.elvin.platform.controller;

import me.chanjar.weixin.api.WxConsts;
import me.chanjar.weixin.api.WxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

@Controller
@RequestMapping("/wx")
public class WeixinController {
  @Autowired
  private WxService wxService;
  @GetMapping("/login")
  public String login(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // 生成state和redirect_uri
    String state = UUID.randomUUID().toString();
    String redirectUri = "http://your_redirect_uri"; // 替换成自己的回调地址
    String redirectUrl = wxService.oauth2buildAuthorizationUrl(redirectUri, WxConsts.OAuth2Scope.SNSAPI_USERINFO, state);

    // 生成带有二维码的页面，并将二维码图片返回给页面
    String qrcodeUrl = wxService.getQrcodeService().qrCodeCreateTmpTicketUrl(redirectUrl, 300);
    String imgHtml = "<img src='" + qrcodeUrl + "'/>";
    return imgHtml;
  }

  @GetMapping("/callback")
  public String callback(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // 处理微信开放平台的回调请求
    String code = request.getParameter("code");
    WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
    WxMpUser wxMpUser = wxService.oauth2getUserInfo(accessToken, null);

    // 将获取到的Access Token和OpenID存储到数据库或缓存中，用于后续的业务处理
    String openId = wxMpUser.getOpenId();
    String accessTokenStr = accessToken.getAccessToken();
    // 存储到数据库或缓存中

    // 返回登录成功页面
    return "login success";
  }
}

*/
